export function formatDate(date, fmt) {
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  }
  let o = {
    'M+': date.getMonth() + 1,
    'd+': date.getDate(),
    'h+': date.getHours(),
    'm+': date.getMinutes(),
    's+': date.getSeconds()
  }
  for (let k in o) {
    if (new RegExp(`(${k})`).test(fmt)) {
      let str = o[k] + ''
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str))
    }
  }
  return fmt
}

export function dateFmt(time){
  let oldDate = new Date(time)
  // let newDate = new Date()
  // var dayNum = "";
  // var getTime = (newDate.getTime() - oldDate.getTime())/1000;

  // if(getTime < 60*5){
  //   dayNum = "刚刚";
  // }else if(getTime >= 60*5 && getTime < 60*60){
  //   dayNum = parseInt(getTime / 60) + "分钟前";
  // }else if(getTime >= 3600 && getTime < 3600*24){
  //   dayNum = parseInt(getTime / 3600) + "小时前";
  // }else if(getTime >= 3600 * 24 && getTime < 3600 * 24 * 30){
  //   dayNum = parseInt(getTime / 3600 / 24 ) + "天前";
  // }else if(getTime >= 3600 * 24 * 30 && getTime < 3600 * 24 * 30 * 12){
  //   dayNum = parseInt(getTime / 3600 / 24 / 30 ) + "个月前";
  // }else if(time >= 3600 * 24 * 30 * 12){
  //   dayNum = parseInt(getTime / 3600 / 24 / 30 / 12 ) + "年前";
  // }

  let year   = oldDate.getFullYear();
  let month  = oldDate.getMonth()+1;
  let day    = oldDate.getDate();
  let hour   = oldDate.getHours();
  let minute = oldDate.getMinutes();
  // let second = oldDate.getSeconds();
  // return dayNum+" "+year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
  return year+"/"+month+"/"+day+" "+hour+":"+minute;
}

function padLeftZero(str) {
  return ('00' + str).substr(str.length)
}
